<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
	String isShow = request.getParameter("isShow") == null ? "" : request.getParameter("isShow");
	String id = request.getParameter("id") == null ? "" : request.getParameter("id");
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
	boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>
<html>
	<head>
		<title><%=isAdd?"新建垫款申请":"编辑垫款申请" %></title>
		<script type="text/javascript" src="<%=contextPath %>/public/js/extend.js"></script>
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
		</style>
	<script type="text/javascript">
		var gdAdminId="";
		var gdAdminName="";
		$(function(){
			if('<%=flag%>' == 1){
				jQuery('#ff').form({
					onLoadSuccess:function(data){
						gdAdminId=data.employee_id;
						gdAdminName=data.employee_name;
					}
				});
		    	jQuery('#ff').form('load','<%=contextPath%>/springMVC/finance/getEmployeeById?id=<%=id%>');
			}else{
				jQuery("#operation_time").datebox('setValue',getTodaySecond());
			}
			jQuery("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			jQuery("#p_dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery('#user_id').combogrid({
				title:'人员选择',
				mode:"remote",
				loadMsg:'正在加载数据，请稍后......',
				panelWidth:550,
				panelHeight:400,
				url:"<%=contextPath%>/springMVC/group/listPageUser",
				idField:"id",
				textField:"truename",
				rownumbers:true,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'deptId',hidden:true},
					{field:'truename',title:'姓名',width:100},
					{field:'deptName',title:'所属部门',width:100},
					{field:'privName',title:'角色',width:100}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					jQuery('#user_id').combogrid('setValue',gdAdminId);
					jQuery('#user_id').combogrid('setText',gdAdminName);

				},
			onChange:function(){
				var row = jQuery('#user_id').combogrid("grid").datagrid('getSelected');
				if(row!=null){
					jQuery('#dept_id').val(row.deptId);
					jQuery('#dept_name').val(row.deptName);
				}

			
			}
			});
		});
		function doSearch() {
			var dept_id = jQuery('#p_dept_id').combotree('getValue');
			var searchValue = jQuery('#searchValue').val();
			jQuery('#user_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id:dept_id
			});
		}
		function doSearch2() {
			var searchValue = jQuery('#searchValue2').val();
			var type_id = jQuery('#type_id').val();
			jQuery('#fb_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				type_id : type_id
				
			});
		}
		function addGDAdvances(obj){
			//自动提交数据
				var money = $("#money").numberbox("getValue");
				var user_id=jQuery('#user_id').combogrid('getValue');
				var user_name=encodeURIComponent(jQuery('#user_id').combogrid('getText'));
				var operation_time=jQuery("#operation_time").datebox('getValue');
				var remark = encodeURIComponent($('#remark').val());
				var title = encodeURIComponent($('#title').val());
				var dept_id = encodeURIComponent($('#dept_id').val());
				var dept_name = encodeURIComponent($('#dept_name').val());
				var param="title="+title+"&money="+money+"&user_id="+user_id+"&user_name="+user_name+"&operation_time="+operation_time+"&remark="+remark+"&dept_id="+dept_id+"&dept_name="+dept_name;
				$(obj).hide();
				$.ajax({
					type:'POST',
					<%=isAdd?"url:'"+contextPath+"/springMVC/finance/addEmployee',":"url:'"+contextPath+"/springMVC/finance/updateEmployee?id="+id+"',"%>
					data:param,
					dataType:'json',
					success:function(rtJson){
						if(rtJson.rtState == '0'){
							eval('window.opener.<%=callback%>();');
							window.close();
						}
						else{
							$.messager.alert("提示",rtJson.rtMsrg);
						}
						$(obj).show();
					}
				});
		}
	</script>
	</head>
	<body>
		<div style="width: 97%;padding-left:10px">
		<form id="ff">
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
			<tr>
					<td align="right" class="td1" nowrap>借款标题：</td>
					<td class="td2" nowrap colspan="3"  >
						<input  id="title" name="title" style="width:99%;"  class="easyui-validatebox"  data-options="required:true" />
					</td>
			</tr>
			<tr>
						
					<td align="right" class="td1" nowrap>借款人：</td>
					<td class="td2" nowrap  >
						<input   id="user_id" name="user_id"/>
						<input type="hidden"  id="user_name" name="user_name" readOnly />
					</td>
					<td align="right" class="td1" nowrap>所属部门：</td>
					<td class="td2" nowrap  >
						<input   id="dept_name" name="dept_name"/>
						<input type="hidden"  id="dept_id" name="dept_id" readOnly />
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>金额：</td>
					<td class="td2" nowrap >
							<input type="text" id="money" name="money" class="easyui-numberbox" data-options="required:true,min:0,precision:2"  />
					</td>
					<td align="right" class="td1" nowrap >申请日期：</td>
					<td class="td2" nowrap  >
						<input  id="operation_time" name="operation_time" class="easyui-datebox" data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>摘要：</td>
					<td class="td2"  colspan='3'>
						<textarea id="remark" name="remark"  style="height:100%;width:99%" rows="6"></textarea>
					</td>
				</tr>
						   <%if(!"1".equals(isShow)){ %>
				<tr>
					<td align="right" class="td1" nowrap></td>
					<td class="td2" nowrap colspan='3'>
						<div align="left">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="addGDAdvances(this);">提交</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
						</div>
					</td>
				</tr>
				<%} %>
			</table>
			</form>
		</div>
		
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>